package com.deerblock.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class AppUtil {
  public static int dp2px(Context context, float dipValue) {
    try {
      final float scale = context.getResources().getDisplayMetrics().density;
      return (int) (dipValue * scale + 0.5f);
    } catch (Exception e) {
      return (int) dipValue;
    }
  }

  public static int px2dp(Context context, float px) {
    try {
      final float scale = context.getResources().getDisplayMetrics().density;
      return (int) (px / scale + 0.5f);
    } catch (Exception e) {
      return (int) px;
    }
  }

  public static int getPhoneWidthPixels(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics var2 = new DisplayMetrics();
    if (wm != null) {
      wm.getDefaultDisplay().getMetrics(var2);
    }

    return var2.widthPixels;
  }

  public static int getPhoneHeightPixels(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics var2 = new DisplayMetrics();
    if (wm != null) {
      wm.getDefaultDisplay().getMetrics(var2);
    }

    return var2.heightPixels;
  }
}
